﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using CustomsSystem.BLL;
using CustomsSystem.Model;
using Maticsoft.Common;
using System.Web.UI.WebControls;
namespace WEB.T_bill
{
    public partial class reject : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.tbTimestart.Attributes.Add("onClick", "new WdatePicker()");
            this.tbTimestop.Attributes.Add("onClick", "new WdatePicker()");
            if (!IsPostBack)
            {
                DateTime A = new DateTime();
                A = DateTime.Today;
                tbTimestop.Text = A.AddDays(1).ToShortDateString();
                tbTimestart.Text = A.AddDays(-30).ToShortDateString();
            }
            bind();
            gridViewClass.GroupRowsR(gvReject, 0, 1, 4, 5, 6, 7, 9);
        }


        public void bind()
        {
            DataSet ds = new DataSet();
            BillManage bll = new BillManage();
            string sql = ""; sql = " billTypeID=" + ddlbillTypeID.SelectedValue + "";
            if (tbTimestart.Text.Trim() != "")
            {
                //日期截止时间为空的时候，默认为现在的时间
                if (tbTimestop.Text.Trim() == "")
                {
                    DateTime timeStop = DateTime.Now;
                    sql = sql + " and inputDate between '" + tbTimestart.Text.Trim() + "' and '" + timeStop + "'";
                }
                else
                {
                    sql = sql + " and inputDate between '" + tbTimestart.Text.Trim() + "' and '" + tbTimestop.Text.Trim() + "'";
                }

            }
            sql += " and auditempid!='0' and payedid!=1 ";
            sql += " order by inputDate " + ddlorder.SelectedValue;
            ds = bll.GetList(sql);
           
            gvReject.DataSource = ds;
            gvReject.DataBind();
            if (gvReject.Rows.Count < 1)
                MessageBox.Show(this, "查无数据");
        }

        /// <summary>
        /// 返审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvReject_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Bill model = new Bill();
            BillManage bll = new BillManage();
            model.billTypeID = int.Parse(ddlbillTypeID.SelectedValue);
            string index = e.CommandArgument.ToString(); //那行被选中,取出选中行的索引 
            model.sheetID = int.Parse(gvReject.Rows[int.Parse(index)].Cells [0].Text.Trim().Trim ().ToString ());
    
            if (e.CommandName == "reject")
            {
                model.auditEmpID ="0";
                model.auditdate =null ;
                if (bll.UpdateAudit(model))
                 MessageBox.ShowAndRedirect(this, "反审核成功", "reject.aspx");
              else
                  MessageBox.ShowAndRedirect(this, "反审核失败", "reject.aspx");
            }
           
           
        }

        /// <summary>
        /// 获取公司名字
        /// </summary>
        /// <returns></returns>
        public DataTable GetCID()
        {
            CustomerManage cus = new CustomerManage();
            DataSet ds = cus.GetList("");
            DataTable dt = ds.Tables[0];
            return dt;

        }

        /// <summary>
        /// 获取费用类别
        /// </summary>
        /// <returns></returns>
        public DataTable GetFeeType()
        {
            FeeTypeManage feeTypeManage = new FeeTypeManage();
            DataSet ds = feeTypeManage.GetAllList();
            DataTable dt = ds.Tables[0];
            return dt;

        }
        /// <summary>
        /// 获取人员表
        /// </summary>
        /// <returns></returns>
        public DataTable GetEmpNum()
        {
            CustomsSystem.BLL.UserManage UserManage = new UserManage();
            DataSet ds = UserManage.GetAllList();
            DataTable dt = ds.Tables[0];
            return dt;

        }
        /// <summary>
        /// 合并同名行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            if (tbTimestart.Text.Trim() == "" || tbTimestop.Text.Trim() == "")
            { MessageBox.Show(this, "请填写时间"); }
            else
            {
                bind();
                gridViewClass.GroupRowsR(gvReject, 0, 1, 4, 5, 6,7,9);
            }
        }

        //protected void gvReject_RowDataBound(object sender, GridViewRowEventArgs e)
        //{
        //    //如果是绑定数据行         
        //    if (e.Row.RowType == DataControlRowType.DataRow)
        //    {
        //        if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
        //        {
        //            ((Button)e.Row.Cells[9].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要对该单进行返审核吗？')");
        //        }
        //    }
        //}

      
    }
}